package org.qiyu.live.api.controller;

import jakarta.annotation.Resource;
import org.qiyu.live.api.service.ILivingRoomService;
import org.qiyu.live.api.vo.LivingRoomInitVO;
import org.qiyu.live.api.vo.red.LivingRoomRedVo;
import org.qiyu.live.common.interfaces.vo.WebResponseVO;
import org.qiyu.live.web.starter.QiyuRequestContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 直播间开关播
 * @Author: 张广焱
 * @Date: 2023-12-13 21:11
 */
@RestController
@RequestMapping("/living")
public class LivingRoomController {
    @Resource
    private ILivingRoomService livingRoomService;

    @PostMapping("/list")
    public WebResponseVO list(LivingRoomRedVo livingRoomRedVo){
        if (livingRoomRedVo ==null || livingRoomRedVo.getType()==null){
            return WebResponseVO.errorParam("需要给定直播间类型");
        }
        if (livingRoomRedVo.getPage()<=0||livingRoomRedVo.getPageSize()>100){
            return WebResponseVO.errorParam("分页参数错误");
        }
        return WebResponseVO.success(livingRoomService.list(livingRoomRedVo));
    }

    @PostMapping("/startingLiving")
    public WebResponseVO startingLiving(Integer type) {
        if (type == null) {
            return WebResponseVO.errorParam("需要给定直播间类型");
        }
        Integer roomId = livingRoomService.startingLiving(type);
        LivingRoomInitVO initVO = new LivingRoomInitVO();
        initVO.setRoomId(roomId);
        return WebResponseVO.success(initVO);
    }

    @PostMapping("/closeLiving")
    private WebResponseVO closeLiving(Integer roomId) {
        if (roomId == null) {
            return WebResponseVO.errorParam("需要给定直播间id");
        }
        boolean closeStatus = livingRoomService.closeLiving(roomId);
        if (closeStatus) {
            return WebResponseVO.success();
        }
        return WebResponseVO.bizError("关播失败");
    }

    /**
     * @Description: 获取主播相关配置信息(只有主播才会有权限)
     * @Param: @param roomID
     * @Author: 张广焱
     * @Date: 2023-12-14  22:50:40
     */
    @PostMapping("/anchorConfig")
    public WebResponseVO anchorConfig(Integer roomID){
        Long userId = QiyuRequestContext.getUserId();
        return WebResponseVO.success(livingRoomService.anchorConfig(userId,roomID));
    }
}
